<?php
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
    $userhaslogin = $auth->getStorage()->read();
    $roleUser = $userhaslogin->group_id;
    ?>
    <div class="menu-demo">
        <div id="accordion">
            <h3><a id="index" href="#" class="pri-subject flag-to-focus-menu">Trang chủ</a></h3>
            <div>
                <p>
                    <a class="" href="<?php echo BASE_URL; ?>/">
                        <img class="fugue fugue-home" alt="" src="<?php echo BASE_URL; ?>/img/icons/space.gif"/>Trang chủ</a>
                </p>
                <p>
                    <a class="" href="<?php echo BASE_URL; ?>/index/intro" >
                        <img class="fugue fugue-heart" alt="" src="<?php echo BASE_URL; ?>/img/icons/space.gif"/>Giới thiệu</a>
                </p>
                <p>
                    <a class="" href="<?php echo BASE_URL; ?>/comment" >
                        <img class="fugue fugue-balloon--pencil" alt="" src="<?php echo BASE_URL; ?>/img/icons/space.gif"/>Trao đổi</a>
                </p>
            </div>
            <?php echo $this->showMenu(); ?>	
            <?php
            $modelGroupUser = new Default_Models_GroupDetail();
            $result = $modelGroupUser->fetchAll("`group_id`='" . $roleUser . "' AND `value`=1 AND `show_menu`=1");
            $ZSN = new Zend_Session_Namespace(NAMESPACE_MAP_APP);
            $MapPermissionApp = $ZSN->__get(NAMESPACE_MAP_APP);
            $MapApp = $MapPermissionApp->getMapApp();

            if (count($MapApp) > 0)
                foreach ($MapApp as $MapAppItem) {
                    $flagLoadIndexAction = 0;
                    // xử lý load cái <h3> kiểm tra xem action index có được show ở menu ko, nếu ko dc thì ko cho load những cái tiếp theo
                    if (count($MapAppItem["actions"]) > 0)
                        foreach ($MapAppItem["actions"] as $actionArr) {
                            if (empty($actionArr['dependence'])) {
                                // So sánh trong csdl xem có được show menu hay ko
                                if (count($result) > 0)
                                    foreach ($result as $resultItem) {
                                        if ($actionArr["name"] == "index")
                                            if ($resultItem->getController() == $MapAppItem["name"] && $resultItem->getAction() == $actionArr["name"] && $resultItem->getShow_menu() == 1) {
                                                ?>
                                                <h3><a id="<?php echo $MapAppItem["name"]; ?>"  href="#" class="pri-subject flag-to-focus-menu"><?php echo $MapAppItem["detail"]; ?></a></h3>
                                                <?php
                                                $flagLoadIndexAction = 1;
                                                break;
                                            }
                                    }
                            }
                        }
                    ?>		

                    <?php
                    if (count($MapAppItem["actions"]) > 0 && $flagLoadIndexAction == 1) {
                        echo "<div>";
                        foreach ($MapAppItem["actions"] as $actionArr) {
                            if (empty($actionArr['dependence'])) {
                                // So sánh trong csdl xem có được show menu hay ko
                                if (count($result) > 0)
                                    foreach ($result as $resultItem) {
                                        if ($resultItem->getController() == $MapAppItem["name"] && $resultItem->getAction() == $actionArr["name"] && $resultItem->getShow_menu() == 1) {
                                            ?>
                                            <p>
                                                    <?php if ($resultItem->getController() == "question" && $actionArr["name"] == "add") { ?>
                                                    <a class="menu_btn_add" href="<?php echo BASE_URL . "/" . $MapAppItem["name"] . "/" . $actionArr["name"]; ?>">
                                                        <?php } else { ?>
                                                        <a class="" href="<?php echo BASE_URL . "/" . $MapAppItem["name"] . "/" . $actionArr["name"]; ?>">
                                    <?php } ?>


                                                    <?php if ($actionArr["name"] == "add") { ?>
                                                            <img class="fugue fugue-folder--plus" alt="" src="<?php echo BASE_URL; ?>/img/icons/space.gif"/><?php echo $actionArr["detail"]; ?></a>	
                                                <?php } elseif ($actionArr["name"] == "index") { ?>
                                                        <img class="fugue fugue-drive--plus" alt="" src="<?php echo BASE_URL; ?>/img/icons/space.gif"/><?php echo $actionArr["detail"]; ?></a>
                                                <?php } else { ?>	
                                                    <img class="fugue fugue-fire" alt="" src="<?php echo BASE_URL; ?>/img/icons/space.gif"/><?php echo $actionArr["detail"]; ?></a>
                                            <?php } ?>
                                            </p>
                                        <?php
                                        }
                                    }
                            }
                        } echo "</div>";
                    }
                    ?>		

        <?php } ?>
        </div>

        <button id="toggle">Ẩn/Hiện</button>
    </div><!-- End demo -->
    <!-- Dialog Add new question -->
    <div id="menu-index-add-question-dialog-container" class="ui-corner-all ui-state-default">
        <h3>Chọn loại câu hỏi</h3>
        <div class="menu-index-add-question-dialog-container-content ui-widget-content">
            <ul>
                <li><button name="<?php echo BASE_URL; ?>/question/addmultichoice">Câu hỏi dạng : nhiều lựa chọn</button></li>
                <li><button name="<?php echo BASE_URL; ?>/question/addtruefalse">Câu hỏi dạng : đúng sai</button></li>
                <li><button name="<?php echo BASE_URL; ?>/question/addmatching">Câu hỏi dạng : ghép cặp</button></li>
                <li><button name="<?php echo BASE_URL; ?>/question/addcompletion">Câu hỏi dạng : điền khuyết</button></li>
                <li><button name="<?php echo BASE_URL; ?>/question/addessaytest">Câu hỏi dạng : tự luận</button></li>
                <li><button name="<?php echo BASE_URL; ?>/question/addshortanswer">Câu hỏi dạng : trả lời ngắn</button></li>
            </ul>			
        </div>
        <div class="footer">
            <input type="button" value="Ðóng" id="btnCloseDialogAddNewQuestion1">
        </div>
    </div>		
    <!-- END Dialog Add new question -->					

<?php } ?>

<script type="text/javascript">
	
    $(document).ready(function(){
	
        // Begin Initialize a accordion
        var icons = {
            header: "ui-icon-circle-arrow-e",
            headerSelected: "ui-icon-circle-arrow-s"
        };
        $( "#accordion" ).accordion({
            autoHeight: false,
            navigation: true,
            icons: icons
        });
		
		
        $( "#toggle" ).button().toggle(function() {
            $( "#accordion" ).accordion( "option", "icons", false );
        }, function() {
            $( "#accordion" ).accordion( "option", "icons", icons );
        });
        // End initialize a accordion		
	
        // Begin Set the active option, after init. 
<?php
// Lấy controller và action so sánh
$controllerName = $this->controllerName;
$actionName = $this->actionName;
?>		
        var ii = 0 ;
        $(".flag-to-focus-menu").each(function(){
            if($(this).attr("id") == "<?php echo $controllerName; ?>")
            {
                $( "#accordion" ).accordion( "option", "active", ii );
            }
            ii++;
        });
    });
</script>

